package com.winchain.chainbill.bill.biz.send.service.impl;

import com.shell.bee.base.utils.StringUtil;
import com.winchain.chainbill.bill.base.po.CbOpt;
import com.winchain.chainbill.bill.base.service.CbOptService;
import com.winchain.chainbill.bill.biz.send.service.BillMsgService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service("billMsgService")
public class BillMsgServiceImpl implements BillMsgService {
	@Autowired
	private CbOptService cbOptService;

	public String getOprId(String billId, String billState) {
		Example example = new Example(CbOpt.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("billId", billId);
		example.setOrderByClause("opt_seq desc");
		List<CbOpt> list = this.cbOptService.selectByExample(example);
		if ((list != null) && (!list.isEmpty())) {
			return ((CbOpt) list.get(0)).getOprId();
		}
		return null;
	}

	public String getOprIdByBillIdAndState(String billId, String curState) {
		Example example = new Example(CbOpt.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("billId", billId);
		if (!StringUtil.emptyAndNull(curState)) {
			criteria.andEqualTo("curState", curState);
		}
		example.setOrderByClause("opt_seq desc");
		List<CbOpt> list = this.cbOptService.selectByExample(example);
		if ((list != null) && (!list.isEmpty())) {
			return ((CbOpt) list.get(0)).getOprId();
		}
		return null;
	}
}
